package com.crr.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {
    /**
     * 向容器中注入交换器
     *
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("publish-ex");
    }

    /**
     * 向容器注入队列queueOne
     * @return
     */
    @Bean
    public Queue queueOne() {
        return new Queue("queueOne");
    }
    /**
     * 向容器注入队列queueTwo
     * @return
     */
    @Bean
    public Queue queueTwo() {
        return new Queue("queueTwo");
    }

    /**
     * 将queueOne队列绑定到交换器
     * @param fanoutExchange 交换器
     * @param queueOne 队列
     * @return
     */
    @Bean
    Binding bindingOne(FanoutExchange fanoutExchange ,Queue queueOne){
        return BindingBuilder.bind(queueOne).to(fanoutExchange);
    }
    /**
     * 将queueOne队列绑定到交换器
     * @param fanoutExchange 交换器
     * @param queueTwo 队列
     * @return
     */
    @Bean
    Binding bindingTwo(FanoutExchange fanoutExchange ,Queue queueTwo){
        return BindingBuilder.bind(queueTwo).to(fanoutExchange);
    }
}
